/*
 * MPlayer.h
 *
 *  Created on: 2018年9月4日
 *      Author: zhengboyuan
 */

#ifndef MPLAYER_H_
#define MPLAYER_H_

#include "LibMediaDecoder.h"
#include <string>
#include "TThread.h"
#include "TEvent.h"
#include "TCriticalSection.h"

#include "FfmpegMediaReader.h"
#include "LoopReader.h"

#include "AVPacketQueue.h"

#include "PacketFile.h"
#include "MediaFormat.h"
#include "TimePoint.h"

#ifdef WIN32
#include "VideoWindow.h"
#endif //WIN32


class MPlayer : public comn::Thread
{
public:
	MPlayer();
	virtual ~MPlayer();

	bool open(const std::string& url);
	void close();

	HANDLE getHandle();

	void inputSubtitle(const std::string& text, int64_t pts);

	void play();
	void pause();

protected:
	virtual int run();
	virtual void doStop();

	virtual void onFace(const std::string& text, int64_t pts);

protected:
	void onInputPacket(AVPacketPtr& pkt);


	bool readFormat(av::MediaFormat& format);
	bool readPacket(AVPacketPtr& pkt);

protected:
	
#ifdef WIN32
	VideoWindow	m_videoWindow;
#endif //WIN32

	std::string	m_url;
	HANDLE	m_handle;
	comn::Event	m_event;

	AVPacketQueue	m_pktQueue;

	bool	m_canPlay;
	
	FILE*	m_file;

	comn::TimePoint	m_timePoint;

};

#endif /* MPLAYER_H_ */
